/**
 * Copyright (c) 2018 软唐 All rights reserved.
 *
 * https://www.softtown.cn
 *
 * 版权所有，侵权必究！
 */

package com.softtown.modules.dapai.controller;

import com.baomidou.mybatisplus.annotation.TableField;
import com.github.pagehelper.PageInfo;
import com.qcloud.cos.utils.StringUtils;
import com.softtown.common.annotation.LogOperation;
import com.softtown.common.exception.ErrorCode;
import com.softtown.common.regularUtils.RegularUtils;
import com.softtown.common.utils.Result;
import com.softtown.modules.dapai.dto.CompCustomerDTO;
import com.softtown.modules.dapai.dto.CustomerAddAppDTO;
import com.softtown.modules.dapai.dto.CustomerAddDTO;
import com.softtown.modules.dapai.dto.CustomerAppDTO;
import com.softtown.modules.dapai.entity.CompCustomerAppEntity;
import com.softtown.modules.dapai.entity.CompCustomerEntity;
import com.softtown.modules.dapai.service.CompCustomerAppService;
import com.softtown.modules.dapai.service.CompCustomerService;
import com.softtown.modules.dapai.vo.CompCityVO;
import com.softtown.modules.dapai.vo.CompCustomerVO;
import com.softtown.modules.dapai.vo.CustomerContactsVO;
import com.softtown.modules.sys.dto.SysMenuDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 客户管理
 *
 * @author Ding Ya Yong
 */
@RestController
@RequestMapping("customer")
@Api(tags="客户管理")
public class CompCustomerController {

    @Resource
    private CompCustomerService compCustomerService;

    @Resource
    private CompCustomerAppService compCustomerAppService;

    @PostMapping("getCustomerPageList")
    @ApiOperation("获取客户管理分页")
    public Result getCustomerPageList(@RequestBody CompCustomerDTO compCustomerDTO) {
        PageInfo<CompCustomerEntity> customerEntityPageInfo = compCustomerService.getCustomerPageList(compCustomerDTO);
        return new Result<PageInfo<CompCustomerEntity>>().ok(customerEntityPageInfo);
    }



    @PostMapping("getCustomerById")
    @ApiOperation("获取客户管理详情")
    public Result<CompCustomerVO> getCustomerById(@RequestBody CompCustomerDTO compCustomerDTO) {
     CompCustomerVO compCustomerVO = compCustomerService.getCustomerById(compCustomerDTO.getCompId(),compCustomerDTO.getId());
        return new Result<CompCustomerVO>().ok(compCustomerVO);
    }


    @PostMapping("addCustomer")
    @ApiOperation("添加客户管理")
    public Result addCustomer(@RequestBody CustomerAddDTO customerAddDTO) {
        Result result = new Result<>();
        compCustomerService.addCustomer(customerAddDTO);
        return result;
    }


    @PostMapping("updateCustomer")
    @ApiOperation("编辑客户管理")
    public Result updateCustomer(@RequestBody CustomerAddDTO customerAddDTO) {
        Result result = new Result<>();
        compCustomerService.updateCustomer(customerAddDTO);
        return result;
    }

    @PostMapping("deleteCustomer")
    @ApiOperation("删除客户管理")
    public Result deleteCustomer(@RequestBody CompCustomerDTO compCustomerDTO) {
        Result result = new Result<>();
        compCustomerService.deleteCustomer(compCustomerDTO.getCompId(),compCustomerDTO.getId());
        return result;
    }


    @PostMapping("getContactsByCustId")
    @ApiOperation("获取客户管理默认联系人")
    public Result<CustomerContactsVO> getContactsByCustId(@RequestBody CompCustomerDTO compCustomerDTO) {
        CustomerContactsVO customerContactsVO = compCustomerService.getContactsByCustId(compCustomerDTO.getCompId(),compCustomerDTO.getId());
        return new Result<CustomerContactsVO>().ok(customerContactsVO);
    }

    @PostMapping("getAllCustomerList")
    @ApiOperation("获取所有客户【下拉】")
    public Result<List<CompCustomerEntity>> getAllCustomerList(@RequestBody CompCustomerDTO compCustomerDTO) {
        List<CompCustomerEntity> list = compCustomerService.getAllCustomerList(compCustomerDTO.getCompId());
        return new Result<List<CompCustomerEntity>>().ok(list);
    }


    @PostMapping("addCustomerApp")
    @ApiOperation("添加app客户管理")
    public Result addCustomerApp(@RequestBody CustomerAddAppDTO customerAddAppDTO) {
        Result result = new Result<>();
        compCustomerAppService.addCustomerApp(customerAddAppDTO);
        return result;
    }


    @PostMapping("updateCustomeApp")
    @ApiOperation("编辑app客户管理")
    public Result updateCustomeApp(@RequestBody CustomerAddAppDTO customerAddAppDTO) {
        Result result = new Result<>();
        compCustomerAppService.updateCustomeApp(customerAddAppDTO);
        return result;
    }

    @PostMapping("deleteCustomerApp")
    @ApiOperation("删除app客户管理")
    public Result deleteCustomerApp(@RequestBody CustomerAddAppDTO customerAddAppDTO) {
        Result result = new Result<>();
        compCustomerAppService.deleteCustomerApp(customerAddAppDTO.getCompId(),customerAddAppDTO.getId());
        return result;
    }

    @PostMapping("getCustomerPageListApp")
    @ApiOperation("获取app客户管理分页")
    public Result getCustomerPageListApp(@RequestBody CustomerAppDTO customerAppDTO) {
        PageInfo<CompCustomerAppEntity> customerEntityPageInfo = compCustomerAppService.getCustomerPageListApp(customerAppDTO);
        return new Result<PageInfo<CompCustomerAppEntity>>().ok(customerEntityPageInfo);
    }



    @PostMapping("getCustomerByIdApp")
    @ApiOperation("获取app客户管理详情")
    public Result<CompCustomerAppEntity> getCustomerByIdApp(@RequestBody CustomerAppDTO customerAppDTO) {
        CompCustomerAppEntity compCustomerAppEntity = compCustomerAppService.getCustomerByIdApp(customerAppDTO.getCompId(),customerAppDTO.getId());
        return new Result<CompCustomerAppEntity>().ok(compCustomerAppEntity);
    }
}